Repository navigation
fix: Switch simulcast layers on a keyframe - #80
Merged
Merged
Conversation
kimsun721
force-pushed
the
fix/78-switch-on-keyframe
branch
from
October 6, 2026 10:34
39a198b to
d5a5dc8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Switch simulcast layers on a keyframe
Why
A layer change took effect on the next frame, which is almost always a delta
frame of the new layer. The viewer's decoder has no reference for it, so the
picture stayed broken until that layer's next keyframe. With OBS that is up to
a full keyframe interval.
Changes
Switching
A viewer's track now holds the layer it is being sent and a target layer. A
layer request records the target and requests its keyframe, and the current
layer keeps flowing. The switch happens when a keyframe of the target arrives,
and that keyframe is the first frame forwarded from the new layer.
layer_changedis sent at the switch, not at the request.of its starting layer.
Viewer protocol
layer_statuscarriescurrent_layerandtarget_layerin place ofchosen_layer.current_layeris null until playback starts.Watch page
The page marks the pending layer and says it is waiting for a keyframe.
A debug mode, from a button or
?debug, logs each switch with how long itwaited, each freeze the browser counts with the packets lost and frames
dropped around it, and any jump in the RTP timestamp.
Keyframes are the publisher's job
The issue listed requesting the keyframe again until it arrives. That is left
out: the server asks once and then waits for a keyframe of the target layer.
OBS sends keyframes on its own interval whether or not it is asked, so a lost
request costs at most one interval. A publisher that sends them only on
request, as a browser does, has to keep an interval of its own.
The README said publishing works from a browser as it does from OBS. It now
names OBS as what is tested, and says that any other WHIP client can publish
but has to send keyframes on an interval.
Tested
Unit tests cover the three cases from the issue: a delta frame of the target
does not switch, a keyframe of another layer does not switch, a keyframe of
the target does. Others cover a new viewer starting on a keyframe, cancelling
a switch, and a repeated request asking once. The integration publisher now
sends media on every layer, since nothing is forwarded before a keyframe.
With OBS sending four layers from 1080p to 270p at 60 fps:
close #78